home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6611 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: kuhub.cc.ukans.edu!anh
  2. From: anh@kuhub.cc.ukans.edu
  3. Newsgroups: comp.lang.c
  4. Subject: unique id for a string
  5. Message-ID: <1996Feb16.175601.114182@kuhub.cc.ukans.edu>
  6. Date: 16 Feb 96 17:56:01 CST
  7. Organization: University of Kansas Academic Computing Services
  8.  
  9.  
  10. Hello,
  11.  
  12. This is not a quite a C problem. But since the implementation will be in 
  13. C anyway.
  14.  
  15. Given an alphabet, for example, E = {A-Z}, I need to assign an unique id 
  16. to each possible strings (finite, approx 32 chars long, or whatever, but 
  17. it is finite) formed by the letters from E. I would like the id to be as 
  18. small as possible. Is there a good formula?
  19.  
  20. Say the alphabet consists of 26 letters. A=1, B=2, ..., Z=6. One formula is:
  21.  
  22. HELLO =  H * 26^4 + E * 26 ^3 +  L * 26^2 + L * 26^1 + E * 26^0
  23.  
  24. But the id is way too big. I need something that fits within a 32-bits int 
  25. or a 64-bits long.
  26.  
  27. Another way is to simply assign a id to a word and store the word in a 
  28. binary search tree, and therefore, it is relatively fast to make sure 
  29. each word has an unique id. But I think it is still to slow. We are 
  30. talking about a possible 200,000+ words.
  31.  
  32. I would appreciate hints/pointers/advice/solutions. Thank-you.
  33.  
  34. Anh
  35.